{%- macro main_menu(data,hierarchy,root) %}
    {% for key, value in hierarchy %}
        {% set iconEncode = base64_encode('icon') %}
        <li{% if key != value %} class="has-son"{% endif %}>
            <a href="{{ url(data[key]['href']) }}">{% if data[key]['attach'][iconEncode] is defined AND data[key]['attach'][iconEncode] %}<i class="{{ stripslashes(data[key]['attach'][iconEncode]) }}"></i>{% endif %} {{ data[key]['name'] }} {% if key != value %}<i class="fa {% if root === true %}fa-angle-down{% else %}fa-arrow-circle-right{% endif %}"></i>{% endif %}
            {% if key != value AND root === true %}
                <i class="fa fa-caret-up" aria-hidden="true"></i>
            {% endif %}
            </a>
            {% if key != value %}
                <ul class="sub-menu">
                    {{ main_menu(data,value,false) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{%- endmacro %}
{{ main_menu(data,hierarchy,true) }}